import axios from '@/libs/api.request'
import {
  format
} from 'path';
import {
  getToken,
  URL
} from "@/libs/util";

// 以防命名冲突
const HOST = URL

/**
 * @param {*} token
 * @param {*} formData  数据
 * @param {*} objKey    对象的KEY
 * @returns
 *
 */

// 县直单位指标数据
function countryUnitMange(formData, keyOne) {
  let data = {}
  data['tokenEntity'] = {
    value: getToken()
  };

  data[keyOne] = {
    id: formData.id, // id
    indexName: formData.indexName, // 指标名
    dateTime: formData.dateTime, // 指标名
    leadUnit: formData.leadUnit, // 考核单位
    pageSize: formData.pageSize, // 显示页数
    pageNumber: formData.pageNumber // 页码

  }
  return data
}

// 县直单位考核数据
function unitAssessmentData(formData, keyOne) {
  let data = {}
  data['tokenEntity'] = {
    value: getToken()
  };

  data[keyOne] = {
    id: formData.id, // id
    indexName: formData.indexName, // 指标名
    dateTime: formData.dateTime, // 指标名
    leadUnit: formData.leadUnit, // 考核单位
    pageSize: formData.pageSize, // 显示页数
    pageNumber: formData.pageNumber // 页码

  }
  return data
}

// 县直单位考核数据二级页面导入表格 数据
function importUnitScoreData(formData, keyOne) {
  let data = {}
  data['tokenEntity'] = {
    value: getToken()
  };

  data[keyOne] = {
    listScore: formData.list[0].listScore, // 表格数据
    id: formData.list[0].uploadId // 行id

  }
  return data
}

// 县直指标二级drawer表格数据
function countryIndexData(formData, keyOne) {
  let data = {}
  data['tokenEntity'] = {
    value: getToken()
  };
  data[keyOne] = {
    id: formData.id, // id
    pageSize: formData.pageSize, // 显示页数
    pageNumber: formData.pageNumber // 页码
  }
  return data
}

/**
 * 县直单位指标管理
 */
export const countryUnitMangeAjax = ({
  formData,
  url,
  keyOne
}) => {
  let data = ''
  data = countryUnitMange(formData, keyOne)
  return axios.request({
    url: HOST + url,
    data,
    method: 'post'
  })
}

/**
 *县直单位考核数据请求
 */
export const unitAssessmentAjax = ({
  formData,
  url,
  keyOne
}) => {
  let data = ''
  data = unitAssessmentData(formData, keyOne)
  return axios.request({
    url: HOST + url,
    data,
    method: 'post'
  })
}

/**
 *县直单位考核数据二级页面导入表格
 */
export const importUnitScoretAjax = ({
  formData,
  url,
  keyOne
}) => {
  let data = ''
  data = importUnitScoreData(formData, keyOne)
  return axios.request({
    url: HOST + url,
    data,
    method: 'post'
  })
}

/**
 * 县直指标详情
 */

export const countryIndexAjax = ({
  formData,
  url,
  keyOne
}) => {
  let data = ''
  data = countryIndexData(formData, keyOne)
  return axios.request({
    url: HOST + url,
    data,
    method: 'post'
  })
}
